<!DOCTYPE html>
<html lang="en">
<title>新增储值卡</title>
<#import "/layout/layout.html" as body/>
<@body.page>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title overflow">
                    <h5 class="pull-left">新增储值卡</h5>
                </div>
                <div class="ibox-content">
                    <form  class="form-horizontal">
                        <input type="hidden" id="id" value="${id!}">
                        <div class="form-group"><h2 class="col-sm-12 margin-top">Step2:内部验证</h2></div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">选择验证人</label>
                            <div class="col-sm-10" id="users">
                                <!--<div class="checkbox-inline i-checks"><label for="is_user3"> <input type="radio" id="is_user3" value="188 8888 0000" name="a"> <i></i> 波波 </label></div>-->
                                <#if checkList??>
                                    <#list checkList as list>
                                        <div class="checkbox-inline i-checks"><label for="${list.id!}"> <input type="radio" id="${list.id!}" value="${list.phone!}" name="a" data-name="${list.name!}"> <i></i> ${list.name!} </label></div>
                                    </#list>
                                </#if>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">发送验证码</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="mobile" value="" style="width: 130px;float: left; border: 0" readonly>
                                <input id="sendCheckCode" type="button" class="btn btn-sm btn-primary btn-rounded" value="发送验证码">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">输入验证码</label>
                            <div class="col-sm-10"><input id="checkCode" class="form-control" placeholder="联系验证人得到验证码"></div>
                        </div>
                        <div class="hr-line-dashed"></div>
                    </form>
                </div>
                <div class="ibox-content overflow">
                    <div class="col-sm-12">
                        <a href="${baseUrl}system/cashcard/to_add_step1?id=${id!}" class="btn btn-default pull-left">返回上一步</a>
                        <button id="submit" type="button" class="btn btn-primary pull-right">确认新增</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="${baseUrl}js/main.js"></script>
<script>
$(document).ready(function () {
    //radio 选择
    $('.i-checks').iCheck({
        checkboxClass: 'icheckbox_square-green',
        radioClass: 'iradio_square-green'
    });

    //选择验证人得到电话号码
    $('#users input').on('ifChecked', function () {
        $('#mobile').val($(this).val());
        console.log($(this).data('name'));
        ;
    });

    //发送验证码
    $("#sendCheckCode").click(function () {
        var mobile = $("#mobile").val();
        if (mobile.trim().length<=0){
            console.log("手机号码为空!");
            swal("手机号码不能为空!","", "error");
            return false;
        }
        var This = this;
        $.post("${baseUrl}system/cashcard/send",{mobile:$("#mobile").val()},function (result) {
            if(result =="success"){
                //验证码发送成功...
                time(This);
            }
            swal({
                title:"验证码发送成功!",
                timer:1000
            }).then(
                function () {},
                // handling the promise rejection
                function (dismiss) {
                    if (dismiss === 'timer') {
                        console.log('I was closed by the timer')
                    }
                }
            )
        });

    });

    //回车绑定
    $(".submit").keydown(function(event){
        if(event.which == "13")
            submit();
    });

    //提交
    $("#submit").click(function (){

        submit();
    });

    //提交
    function submit() {
        $.post("${baseUrl}system/cashcard/check",
            {
                checkCode: $("#checkCode").val(),
                id: $("#id").val(),
                mobile: $("#mobile").val(),
                checkName: $("input[type='radio'][name='a']:checked").data('name')
            },
            function (result) {
                debugger
                if (result == "success") {
                    swal("验证成功!", "该新储值卡券ID为: "+$("#id").val()+" ,页面即将重新加载,请稍后...", "success");
                    window.setTimeout(function () {
                        window.location = '${baseUrl}system/cashcard/to_cashcard_list'
                    }, 1000);
                } else {
                    swal({title: result});
                }
            });
    }


    var wait = 60;
    function time(o) {
        if (wait == 0) {
            o.removeAttribute("disabled");
            o.value = "发送验证码";
            wait = 60;
        } else {
            o.setAttribute("disabled", true);
            o.value = "重新发送(" + wait + ")";
            wait--;
            setTimeout(function () {
                time(o)
            }, 1000)
        }
    }

});
</script>
</@body.page>
</html>